﻿<Window x:Class="FileSysExp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:models ="clr-namespace:FileSysExp.Models"
        Background="{StaticResource BackgroundBrush}"
        Title="File System Viewer" MinHeight="400" MinWidth="525">
    <Window.Resources>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
            <Setter Property="BorderBrush" Value="{StaticResource DarkBorderBrush}"/>
            <Setter Property="BorderThickness" Value="0,0,0,1"/>
            <Setter Property="Padding" Value="3"/>
            <Setter Property="MinHeight" Value="24"/>
            <Setter Property="MinWidth" Value="120"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="24"/>
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="240"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TreeView x:Name="FileSystemTree" Margin="0,23,0,0"
                      Background="{StaticResource LightBackgroundBrush}"
                      BorderBrush="{StaticResource DarkBorderBrush}"
                      BorderThickness="0,1,1,0"
                      ScrollViewer.CanContentScroll="True" 
                      ScrollViewer.HorizontalScrollBarVisibility="Auto"
                      ScrollViewer.VerticalScrollBarVisibility="Auto" 
                      DockPanel.Dock="Left"
                      ItemsSource="{Binding Path=Directories}" 
                      SelectedItemChanged="FileSystemTree_SelectedItemChanged">
                <TreeView.Resources>
                    <HierarchicalDataTemplate DataType="{x:Type models:DirItemViemModel}"
                                          ItemsSource="{Binding Children}">
                        <StackPanel Orientation="Horizontal">
                            <Image Margin="0,3" Source="{Binding Icon}"/>
                            <TextBlock Margin="3,3" Text="{Binding ShortName}"/>
                        </StackPanel>
                    </HierarchicalDataTemplate>
                </TreeView.Resources>
            </TreeView>
            <DataGrid Grid.Column="1" 
                      x:Name="dataGrid"
                      BorderThickness="0"
                      AutoGenerateColumns="False"   
                      MinWidth="400" 
                      CanUserAddRows="False"
                      CanUserDeleteRows="False"
                      CanUserReorderColumns="False"
                      CanUserResizeRows="False"
                      HeadersVisibility="Column"
                      Background="{StaticResource LightBackgroundBrush}"
                      GridLinesVisibility="None"
                      ItemsSource="{Binding Path=SelectedItem.Children}"
                      SelectedCellsChanged="DataGrid_SelectedCellsChanged">
                <DataGrid.CellStyle>
                    <Style TargetType="{x:Type DataGridCell}">
                        <Setter Property="BorderBrush" Value="Transparent"/>
                        <Setter Property="Background" Value="{StaticResource LightBackgroundBrush}"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type DataGridCell}">
                                    <Border BorderBrush="{TemplateBinding BorderBrush}" 
                                            Padding="3"
                                            Background="{TemplateBinding Background}">
                                        <ContentPresenter Content="{TemplateBinding Content}"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter Property="Foreground" Value="White"/>
                                <Setter Property="Background" Value="{StaticResource HighlightBackgroudBrush}"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.CellStyle>
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="Name">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding Icon}"/>
                                    <TextBlock Text="{Binding ShortName}"/>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn  Binding="{Binding Path=ModifiedDate}" Header="Last Access Time" Foreground="{StaticResource LightForegroundBrush}"/>
                    <DataGridTextColumn  Binding="{Binding Path=Size}" Header="Size" Width="*" Foreground="{StaticResource LightForegroundBrush}"/>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
        <Border Grid.Row="1" Background="{StaticResource BackgroundBrush}" BorderThickness="0,1,0,0" BorderBrush="{StaticResource DarkBorderBrush}" >
            <TextBlock Padding="3" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding Path=SelectedItem.Name}"/>
        </Border>
    </Grid>

</Window>
